#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：Employment_class 
@File    ：10_单进程服务器.py
@IDE     ：PyCharm 
@Author  ：XiaoDengYa
@Date    ：2021/7/6/006 9:32 
"""

from socket import *

serSocket = socket(AF_INET, SOCK_STREAM)

serSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

serSocket.bind(("",7789))

serSocket.listen(5)

while True:
    print('-----主进程，，等待新客户端的到来------')
    clinetSocket, destAddr = serSocket.accept()
    print('-----主进程，，接下来负责数据处理[%s]-----' % str(destAddr))
    try:
        while True:
            recvData = clinetSocket.recv(1024)
            if recvData:
                print('recv[%s]:%s' % (str(destAddr), recvData))
            else:
                print('[%s]客户端已经关闭' % str(destAddr))
                break
    finally:
        clinetSocket.close()
    break
serSocket.close()



